using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VWZPOS
    {
        public DataRow Convert2WZPOS(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryWZPOS(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["WZPMANDANT"] = " ".PadRight(2 ); 
         dwReturn["WZPREGEL"] = " ".PadRight(8 ); 
         dwReturn["WZPME"] = " ".PadRight(1 ); 
         dwReturn["WZPMENGE"] = " ".PadRight(0 ); 
         dwReturn["WZPAENZL"] = " ".PadRight(0 ); 
         dwReturn["WZPAENB"] = " ".PadRight(8 ); 
         dwReturn["WZPAEND"] = " ".PadRight(0 ); 
         dwReturn["WZPNEUB"] = " ".PadRight(8 ); 
         dwReturn["WZPNEUD"] = " ".PadRight(0 ); 
         dwReturn["WZPLIEFMEV"] = " ".PadRight(0 ); 
         dwReturn["WZPLIEFMEB"] = " ".PadRight(0 ); 
         dwReturn["WZPDSTLGV"] = " ".PadRight(0 ); 
         dwReturn["WZPDSTLGB"] = " ".PadRight(0 ); 
         dwReturn["WZPSTLGV"] = " ".PadRight(0 ); 
         dwReturn["WZPSTLGB"] = " ".PadRight(0 ); 
         dwReturn["WZPPA"] = " ".PadRight(0 ); 
         dwReturn["WZPTST"] = " ".PadRight(0 ); 
         dwReturn["WZPTSTLG"] = " ".PadRight(0 ); 
         dwReturn["WZPOFFEN"] = " ".PadRight(0 ); 
         dwReturn["WZPOBERGR"] = " ".PadRight(1 ); 
         dwReturn["WZPFILLER"] = " ".PadRight(26 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapWZPOS(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveWZPOS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWZPOS(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWZPOS(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertWZPOS(dwLocal, ITXDBVERSION);
            }
            UpdateWZPOS(dwLocal);
        }
        public void InsertWZPOS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO WZPOS(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryWZPOS(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM WZPOS WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM WZPOS  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "WZPOS";
            Return = Result;
            return Return;
        }
        public void DeleteWZPOS(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM WZPOS   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateWZPOS(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE WZPOS SET "
                    +"WZPMANDANT= :WZPMANDANT,"
                    +"WZPREGEL= :WZPREGEL,"
                    +"WZPME= :WZPME,"
                    +"WZPMENGE= :WZPMENGE,"
                    +"WZPAENZL= :WZPAENZL,"
                    +"WZPAENB= :WZPAENB,"
                    +"WZPAEND= :WZPAEND,"
                    +"WZPNEUB= :WZPNEUB,"
                    +"WZPNEUD= :WZPNEUD,"
                    +"WZPLIEFMEV= :WZPLIEFMEV,"
                    +"WZPLIEFMEB= :WZPLIEFMEB,"
                    +"WZPDSTLGV= :WZPDSTLGV,"
                    +"WZPDSTLGB= :WZPDSTLGB,"
                    +"WZPSTLGV= :WZPSTLGV,"
                    +"WZPSTLGB= :WZPSTLGB,"
                    +"WZPPA= :WZPPA,"
                    +"WZPTST= :WZPTST,"
                    +"WZPTSTLG= :WZPTSTLG,"
                    +"WZPOFFEN= :WZPOFFEN,"
                    +"WZPOBERGR= :WZPOBERGR,"
                    +"WZPFILLER= :WZPFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("WZPMANDANT", OracleType.NVarChar).Value = dwData["WZPMANDANT"].ToString(); 
          or1.Parameters.Add("WZPREGEL", OracleType.NVarChar).Value = dwData["WZPREGEL"].ToString(); 
          or1.Parameters.Add("WZPME", OracleType.NVarChar).Value = dwData["WZPME"].ToString(); 
          or1.Parameters.Add("WZPMENGE", OracleType.NVarChar).Value = dwData["WZPMENGE"].ToString(); 
          or1.Parameters.Add("WZPAENZL", OracleType.NVarChar).Value = dwData["WZPAENZL"].ToString(); 
          or1.Parameters.Add("WZPAENB", OracleType.NVarChar).Value = dwData["WZPAENB"].ToString(); 
          or1.Parameters.Add("WZPAEND", OracleType.NVarChar).Value = dwData["WZPAEND"].ToString(); 
          or1.Parameters.Add("WZPNEUB", OracleType.NVarChar).Value = dwData["WZPNEUB"].ToString(); 
          or1.Parameters.Add("WZPNEUD", OracleType.NVarChar).Value = dwData["WZPNEUD"].ToString(); 
          or1.Parameters.Add("WZPLIEFMEV", OracleType.NVarChar).Value = dwData["WZPLIEFMEV"].ToString(); 
          or1.Parameters.Add("WZPLIEFMEB", OracleType.NVarChar).Value = dwData["WZPLIEFMEB"].ToString(); 
          or1.Parameters.Add("WZPDSTLGV", OracleType.NVarChar).Value = dwData["WZPDSTLGV"].ToString(); 
          or1.Parameters.Add("WZPDSTLGB", OracleType.NVarChar).Value = dwData["WZPDSTLGB"].ToString(); 
          or1.Parameters.Add("WZPSTLGV", OracleType.NVarChar).Value = dwData["WZPSTLGV"].ToString(); 
          or1.Parameters.Add("WZPSTLGB", OracleType.NVarChar).Value = dwData["WZPSTLGB"].ToString(); 
          or1.Parameters.Add("WZPPA", OracleType.NVarChar).Value = dwData["WZPPA"].ToString(); 
          or1.Parameters.Add("WZPTST", OracleType.NVarChar).Value = dwData["WZPTST"].ToString(); 
          or1.Parameters.Add("WZPTSTLG", OracleType.NVarChar).Value = dwData["WZPTSTLG"].ToString(); 
          or1.Parameters.Add("WZPOFFEN", OracleType.NVarChar).Value = dwData["WZPOFFEN"].ToString(); 
          or1.Parameters.Add("WZPOBERGR", OracleType.NVarChar).Value = dwData["WZPOBERGR"].ToString(); 
          or1.Parameters.Add("WZPFILLER", OracleType.NVarChar).Value = dwData["WZPFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
